import React,{useEffect} from 'react';
import { observer, ResizeListener, unobserver } from "./observerUtil";


function UseObserve({
    currenDom,
    disabled,
    onInternalResize
}:{
    currenDom:HTMLDivElement|null;
    disabled:boolean;
    onInternalResize:ResizeListener
}) {
  useEffect(()=>{
    if(currenDom && !disabled){
        // 监听
        observer(currenDom,onInternalResize)
    }
    return ()=>{
        unobserver(currenDom,onInternalResize)
    }
  },[currenDom,disabled])
}

export default UseObserve;
